package com.nmgsr.ptmsapp.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.github.abel533.echarts.json.GsonOption;
import com.google.gson.Gson;
import com.nmgsr.nettools.base.BaseActivity;
import com.nmgsr.ptmsapp.R;
import com.nmgsr.ptmsapp.databinding.MyechatsActivityBinding;
import com.nmgsr.ptmsapp.utils.EchartOptionUtil;
import com.nmgsr.ptmsapp.view.EchartView;

public class MyEchatsActivity extends BaseActivity {
    private EchartView eChart;
    private MyechatsActivityBinding mBinding;
    @Override
    protected int getLayoutId() {
        return R.layout.myechats_activity;
    }
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        mBinding = MyechatsActivityBinding.inflate(getLayoutInflater());
        View view = mBinding.getRoot();
        setContentView(view);
        mBinding.echartView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                refreshEchart();
            }
        });

    }
    protected void onResume() {
        super.onResume();
        refreshEchart();
    }

    private void refreshEchart(){
        Object[] x = new Object[]{
                "1", "2", "3", "4", "5", "6", "7"
        };
        Object[] y = new Object[]{
                12, 23, 34, 45, 56, 78, 90
        };
        GsonOption option = EchartOptionUtil.getLineChartOptions(x, y);
        Log.d("EchartOption", new Gson().toJson(option));
        mBinding.echartView.refreshEchartsWithOption(new Gson().toJson(option));
    }

}
